﻿<?php

session_start();

//Pear & Propel Stuffs
set_include_path(get_include_path() .PATH_SEPARATOR. "../../../libs/pear");
set_include_path(get_include_path() .PATH_SEPARATOR. "../../../libs/propel/runtime/lib");
set_include_path(get_include_path() .PATH_SEPARATOR. "../../../bdd/build/classes");
require_once '../../../libs/propel/runtime/lib/Propel.php';
Propel::init("../../../bdd/build/conf/tshirtfactory-conf.php");

print_r($_POST['customerBis']);
$adresse = new Adresse();
$adresse->setTitre($_POST['customer']['title'] == 'Mr' ? 0 : 1);
$adresse->setNom(urldecode($_POST['customer']['name']));
$adresse->setPrenom(urldecode($_POST['customer']['firstname']));
$adresse->setAdresse(urldecode($_POST['customer']['address']));
$adresse->setPostal(urldecode($_POST['customer']['postalCode']));
$adresse->setVille(urldecode($_POST['customer']['city']));
$adresse->setTel(urldecode($_POST['customer']['phone']));
$adresse->save();

$user = new Client();


if($_POST['customerBis'] != NULL){
	$adresseDelivery = new Adresse();
	$adresseDelivery->setTitre($_POST['customerBis']['titleDelivery'] == 'Mr' ? 0 : 1);
	$adresseDelivery->setNom(urldecode( $_POST['customerBis']['nameDelivery']));
	$adresseDelivery->setPrenom(urldecode( $_POST['customerBis']['firstnameDelivery']));
	$adresseDelivery->setAdresse(urldecode( $_POST['customerBis']['addressDelivery']));
	$adresseDelivery->setPostal(urldecode( $_POST['customerBis']['postalCodeDelivery']));
	$adresseDelivery->setVille(urldecode( $_POST['customerBis']['cityDelivery']));
	$adresseDelivery->setTel(urldecode( $_POST['customerBis']['phoneDelivery']));
	$adresseDelivery->save();
	
	$user->setFacturation($adresseDelivery->getId());
} else {
	$user->setFacturation(NULL);
}

$user->setAdresse($adresse->getId());
$user->setEmail($_POST['customer']['mail']);
$user->setPassword(md5($_POST['customer']['password']));
$user->save();

